import PropTypes from 'prop-types'

function myValidate(props,propName,componentName) {
  if (Number.isInteger(props[propName]) && props[propName] >= 0 && props[propName] <= 100) {
    return null //成功
  } else {
    return new Error(`${componentName}的属性${propName}必须是整数`+`,且>=0,<=100`)
  }
}
function Commit({
  author,/*作者*/
  message,/*内容*/
  likes/*点赞数*/
})
{
  return (
    <div>
      <div className='author'>{author.name}</div>
      <div className='message'>{message}</div>
      <div className='likes'>
        {likes > 0 ? `${likes}人点赞` :`无人赞赏`}
      </div>
    </div>
  )
}
Comment.propTypes ={
  message: PropTypes.string,
  // author: PropTypes.string.isRequired,/*警告，非错误*/
  author: PropTypes.shape({
    name: PropTypes.string,
    age:PropTypes.number
  }),
  likes: PropTypes.number,
  topic: PropTypes.oneOf(['时尚', '影视', '闲聊']),
  hot: myValidate
}
/*
<Comment topic='游戏'/>
class Comment extends React.Component{
  ststic propTypes = {
    ...
  }
}
*/ 
export default Commit